<?php
class main extends top
{
	//重定义构造函数
    function __construct(){  
        parent::__construct();
        //定义当前导航
        $this->nav_name = 'index';
        $this->page_title = '首页';
    }
    //构造左侧导航
    function __left_nav_common(){
    	/*
		$left_nav_result = array(
				array(
						'id'=>1,
						'name'=>'文章管理',
						'url'=>spUrl('article'),
					),
				array(
						'id'=>1,
						'name'=>'相册管理',
						'url'=>spUrl('picture'),
					),
				array(
						'id'=>1,
						'name'=>'专题管理',
						'url'=>spUrl('page'),
					),
				array(
						'id'=>1,
						'name'=>'链接管理',
						'url'=>spUrl('url'),
					),
			);
		*/
		$this->left_nav_result = $left_nav_result;
		//var_dump($this->nav_result); 	
    }
	function index(){
		
		$this->__left_nav_common();
	}
	function login(){
		$data = $this->spArgs();
		if(isset($data['state'])&&isset($data['message'])){
			$this->notice = array($data['state'],$data['message']);
		}
		if(isset($data['name'])&&isset($data['password'])){
			$this->login_verify();
		}
	}
	function login_verify(){	
		$user = spClass('m_user');
		$login_result = $user->find(array('name'=>$this->spArgs('name','','post')));
		if($login_result){				
			if($login_result['password']==md5($this->spArgs('password','','post')."ytcms")){
				$_SESSION['ID'] = $login_result['id'];
				$_SESSION['USER'] = $login_result['name'];
				$_SESSION['POWER'] = $login_result['power_grade'];
				$_SESSION['PASS'] = md5($login_result['password'].'check_session');
				$user->incrField('id='.$login_result['id'], 'login_time');
				$this->jump(spUrl('main', 'index'));
			}else{
				//密码不正确
				$this->jump(spUrl('main', 'login',array('state'=>'danger','message'=>'密码不正确')));
			}
		}else{
				//用户名不存在
				$this->jump(spUrl('main', 'login',array('state'=>'danger','message'=>'用户名不存在')));
		}
	}
}